//
//  NFSJSBridgeHelper.m
//  NetEaseFinancial
//
//  Created by 吴玉峰 on 8/17/15.
//  Copyright (c) 2015 吴玉峰. All rights reserved.
//

#import "NFSJSBridgeHelper.h"

#import "WYFJSCommand.h"
#import "WYFJSBridge.h"
#import "WYFWebViewProxyDelegate.h"

#import "WYFShareHolder.h"
#import "NFSSharePanel.h"


@interface NFSJSBridgeHelper () <UIWebViewDelegate>

@property (nonatomic, weak) WYFWebViewProxyDelegate *webViewProxyDelegate;
@property (nonatomic, strong) WYFJSBridge *jsBridge;
@property (nonatomic, strong) NSMutableDictionary *webViewActionListenerMap;


@end

@implementation NFSJSBridgeHelper



/******    .h    **********/
- (instancetype)initWithWebViewProxyDelegate:(WYFWebViewProxyDelegate *)webViewProxyDelegate {
    if ((self = [super init])) {
        self.webViewProxyDelegate = webViewProxyDelegate;
        self.webViewActionListenerMap = [NSMutableDictionary dictionaryWithCapacity:16];
        self.jsBridge = [[WYFJSBridge alloc] initWithWebViewProxyDelegate:self.webViewProxyDelegate];
        [self registerCommands];
    }
    return self;
}

/******    .h    **********/
- (void)addWebViewActionListener:(NSString *)actionName listener:(id)listener {
    self.webViewActionListenerMap[actionName] = listener;
}
/******    .h    **********/
- (void)executeJsFunctionWithCmdName:(NSString *)cmdName params:(NSDictionary *)params jsCallback:(id)jsCallback {
    [self.jsBridge execute:cmdName params:params jsCallback:jsCallback];
}


/******    .h    **********/
- (void)registerCommands {
    [self.jsBridge registerCommandWithName:REQUEST_JS_SHARE_ON_WE_CHAT_MOMENT
                        objectiveCFunction:^(WYFJSCommand *cmd) {
                        
                        }];

    [self.jsBridge registerCommandWithName:REQUEST_JS_SEND_TO_WE_CHAT_FRIEND
                        objectiveCFunction:^(WYFJSCommand *cmd) {
                     
                        }];

    [self.jsBridge registerCommandWithName:REQUEST_JS_SHARE_ON_EASY_CHAT_MOMENT
                        objectiveCFunction:^(WYFJSCommand *cmd) {
                     
                        }];

    [self.jsBridge registerCommandWithName:REQUEST_JS_SEND_TO_EASY_CHAT_FRIEND
                        objectiveCFunction:^(WYFJSCommand *cmd) {
                            
                        }];

    [self.jsBridge registerCommandWithName:REQUEST_JS_SHOW_SHARE_PANEL
                        objectiveCFunction:^(WYFJSCommand *cmd) {
                            
                            NSLog(@"//   推荐富聪社给好友  //  %@",cmd);
                            
                            WYFShareHolder *holder = [[WYFShareHolder alloc] initWithJson:cmd.params];
                            NFSSharePanel *sharePanel = [[NFSSharePanel alloc] initSharePanelWithHolder:holder cmd:cmd];
                            [sharePanel show];

                     
                        }];

    [self.jsBridge registerCommandWithName:REQUEST_JS_CHOOSE_IMAGE
                        objectiveCFunction:^(WYFJSCommand *cmd) {
                        }];

    [self.jsBridge registerCommandWithName:REQUEST_JS_REFRESH_PAGE
                        objectiveCFunction:^(WYFJSCommand *cmd) {
                        }];

    [self.jsBridge registerCommandWithName:REQUEST_JS_SHOW_OPTION_MENU
                        objectiveCFunction:^(WYFJSCommand *cmd) {
                        }];

    [self.jsBridge registerCommandWithName:REQUEST_JS_HIDE_OPTION_MENU
                        objectiveCFunction:^(WYFJSCommand *cmd) {
                        }];

    [self.jsBridge registerCommandWithName:REQUEST_JS_ON_MENU_SHARE
                        objectiveCFunction:^(WYFJSCommand *cmd) {
                        }];
    [self.jsBridge registerCommandWithName:REQUEST_JS_CLEAR_WEB_CACHE
                        objectiveCFunction:^(WYFJSCommand *cmd){
                            NSLog(@"clear cache");
    }];
    

    [self.jsBridge registerCommandWithName:REQUEST_JS_SET_ALIAS_AND_TAGS
             objectiveCFunction:^(WYFJSCommand *cmd){
                 
             }];

    [self.jsBridge registerCommandWithName:REQUEST_JS_RESUME_PUSH
                        objectiveCFunction:^(WYFJSCommand *cmd){
                            //                            JPushInterface.resumePush(mContext));
                        }];

    [self.jsBridge registerCommandWithName:REQUEST_JS_STOP_PUSH
                        objectiveCFunction:^(WYFJSCommand *cmd){
                            //                        JPushInterface.stopPush(mContext));
                        }];

    [self.jsBridge registerCommandWithName:REQUEST_JS_GET_VERSION_NAME
                        objectiveCFunction:^(WYFJSCommand *cmd) {
     
                        }];

    [self.jsBridge registerCommandWithName:REQUEST_JS_IS_LOGIN_TIME_OUT
                        objectiveCFunction:^(WYFJSCommand *cmd){
           
                        }];

    // 获取应用版本号,版本号为整数类型
    [self.jsBridge registerCommandWithName:REQUEST_JS_GET_VERSION_CODE
                        objectiveCFunction:^(WYFJSCommand *cmd) {
                      
                            NSLog(@"// 获取应用版本号,版本号为整数类型  //  %@",cmd);
                            
                            
                        }];

    // 获取登陆NFS服务器所需的appId
    [self.jsBridge registerCommandWithName:PARAM_NATIVE_APP_ID
                        objectiveCFunction:^(WYFJSCommand *cmd) {
                
                        }];

    // 获取登陆NFS服务器所需的appSecret
    [self.jsBridge registerCommandWithName:PARAM_NATIVE_APP_SECRET
                        objectiveCFunction:^(WYFJSCommand *cmd) {
                       
                        }];

    // 获取UUID
    [self.jsBridge registerCommandWithName:PARAM_JS_DEVICE_ID
                        objectiveCFunction:^(WYFJSCommand *cmd) {

                        }];

    // 展示PDF
    [self.jsBridge registerCommandWithName:REQUEST_JS_PREVIEW_ONLINE_FILE
                        objectiveCFunction:^(WYFJSCommand *cmd) {

                        }];

    //
    [self.jsBridge registerCommandWithName:REQUEST_JS_UPDATE_APP
                        objectiveCFunction:^(WYFJSCommand *cmd){
                     
                        }];

    [self.jsBridge registerCommandWithName:REQUEST_JS_IS_APP_NEED_FORCE_UPDATE
                        objectiveCFunction:^(WYFJSCommand *cmd) {
                 
                        }];

    [self.jsBridge registerCommandWithName:REQUEST_JS_SET_UNREAD_PRIVATE_MESSAGE_COUNT
                        objectiveCFunction:^(WYFJSCommand *cmd) {
          
                        }];
    [self.jsBridge registerCommandWithName:REQUEST_JS_SHOW_LOCK_PATTERN_CREATE_SCREEN
                        objectiveCFunction:^(WYFJSCommand *cmd) {
                

                        }];

    [self.jsBridge registerCommandWithName:REQUEST_JS_IS_LOCK_PATTERN_EXISTS
                        objectiveCFunction:^(WYFJSCommand *cmd) {

                        }];

    [self.jsBridge registerCommandWithName:REQUEST_JS_SHOW_LOCK_PATTERN_RESET_SCREEN
                        objectiveCFunction:^(WYFJSCommand *cmd) {
                            
                            NSLog(@"你大爷的");

                        }];

    [self.jsBridge registerCommandWithName:REQUEST_JS_GET_FORTUNE_CLUB_API_LEVEL
                        objectiveCFunction:^(WYFJSCommand *cmd){
                            NSDictionary *result = @{PARAM_NATIVE_API_LEVEL: API_LEVEL};
                            [cmd setResult:result];
                        }];

    [self.jsBridge registerCommandWithName:REQUEST_JS_SET_TITLE
                        objectiveCFunction:^(WYFJSCommand *cmd) {
                            NSLog(@"set title");
        
                        }];
}





@end
